#include "thread.h"
#include <QTimer>
#include <QFile>
#include <QEventLoop>
#include <QTime>

Thread::Thread()
{

}

Thread::Thread(QString filepath)
{
    this->filepath = filepath;
}

void Thread::startWork()
{
    QFile file(filepath);
    for (int i = 0; i < 100; ++i)
    {
        QMutexLocker locker(&mutex);
        if (!file.open(QIODevice::Append | QIODevice::Text))
        {
            emit finished();
            return;
        }
        file.write(QString::number(i).toUtf8() + "你好，“文件”"+ QTime::currentTime().toString("hh:mm:ss.zzz").toUtf8() +"\n");
        file.close();
        QThread::msleep(500);
    }
    emit finished();
}
